package com.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mapper.SysUserMapper;
import com.example.pojo.SysUser;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Collection;

@Service
public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements UserService {
    @Override
    public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException {
        SysUser userEntity = baseMapper.selectById(id);
        if (userEntity!=null){
            //创建角色集合对象
            Collection<GrantedAuthority> authorities = new ArrayList<>();
            User user = new User(userEntity.getId().toString(), userEntity.getPassword(), authorities);
            return user;
        }
        return null;
    }
}
